package org.stu.tp.testCases.contact;

import org.stu.tp.core.DefaultAjaxSelenium;

public class ContactSac extends ContactBaseSac {

	// set and get baseInfo
	/**
	 * @param selenium
	 * @return
	 */
	public String getName(DefaultAjaxSelenium selenium) {
		return selenium.getText("txtName");
	}

	public void setName(DefaultAjaxSelenium selenium, String name) {
		selenium.type("txtName", name);
	}

	public String getCompany(DefaultAjaxSelenium selenium) {
		return selenium.getText("txtComp");
	}

	public void setCompany(DefaultAjaxSelenium selenium, String company) {
		selenium.type("txtComp", company);
	}

	public String getDepart(DefaultAjaxSelenium selenium) {
		return selenium.getText("txtDept");
	}

	public void setDepart(DefaultAjaxSelenium selenium, String depart) {
		selenium.type("txtDept", depart);
	}

	// set and get detailInfo
	/**
	 * @param selenium
	 * @return
	 * 
	 */
	public String getRealName(DefaultAjaxSelenium selenium) {
		return selenium.getText("txtRealName");
	}

	public void setRealName(DefaultAjaxSelenium selenium, String realName) {
		selenium.type("txtRealName", realName);
	}

	public String getBorn(DefaultAjaxSelenium selenium) {
		return selenium.getText("txtBirthday");
	}

	public void setBorn(DefaultAjaxSelenium selenium, String born) {
		selenium.type("txtBirthday", born);
	}

	public String getSex(DefaultAjaxSelenium selenium) {
		String sex = "male";
		if (selenium.getValue("rbtnGirl").equals("on")) {
			sex = "female";
		}
		return sex;
	}

	public void setSex(DefaultAjaxSelenium selenium, String sex) {
		if (sex.equals("male")) {
			selenium.click("rbtnBoy");
		} else {
			selenium.click("rbtnGirl");
		}
	}

	public String getAddress(DefaultAjaxSelenium selenium) {
		return selenium.getText("txtAddress");
	}

	public void setAddress(DefaultAjaxSelenium selenium, String address) {
		selenium.type("txtAddress", address);
	}

	public String getRemark(DefaultAjaxSelenium selenium) {
		return selenium.getText("txtRemark");
	}

	public void setRemark(DefaultAjaxSelenium selenium, String remark) {
		selenium.type("txtRemark", remark);
	}

	// set and get phones
	/**
	 * @param selenium
	 * @param index
	 *            It should be the format as "1"! offset from "1"!
	 * @return
	 */
	public String getPhoneNumber(DefaultAjaxSelenium selenium, String index) {
		return selenium.getText("//input[@name='txtPhone_" + index + "']");
	}

	public void setPhoneNumber(DefaultAjaxSelenium selenium, String index,
			String number) {
		selenium.type("//input[@name='txtPhone_" + index + "']", number);
	}

	/**
	 * @param selenium
	 * @param index
	 *            It should be the format as "1"! offset from "1"!
	 * @return return the label of the selected option
	 */
	public String getPhoneType(DefaultAjaxSelenium selenium, String index) {
		return selenium.getSelectedLabel("//select[@name='ddlPhoneType_"
				+ index + "']");
	}

	/**
	 * @param selenium
	 * @param index
	 *            It should be the format as "1"! offset from "1"!
	 * @param type
	 *            should be the label of the option
	 * @return
	 */
	public void setPhoneType(DefaultAjaxSelenium selenium, String index,
			String type) {
		selenium.select("//select[@name='ddlPhoneType_" + index + "']", type);
	}

	/**
	 * @param selenium
	 * @param index
	 *            It should be the format as "1"! offset from "1"!
	 * @return return the label of the selected option
	 */
	public String getPhoneProvince(DefaultAjaxSelenium selenium, String index) {
		return selenium.getSelectedLabel("//select[@name='ddlProvince_" + index
				+ "']");
	}

	/**
	 * @param selenium
	 * @param index
	 *            It should be the format as "1"! offset from "1"!
	 * @param province
	 *            should be the label of the option
	 */
	public void setPhoneProvince(DefaultAjaxSelenium selenium, String index,
			String province) {
		selenium.select("//select[@name='ddlProvince_" + index + "']", province);
	}

	/**
	 * @param selenium
	 * @param index
	 *            It should be the format as "1"! offset from "1"!
	 * @return return the label of the selected option
	 */
	public String getPhoneState(DefaultAjaxSelenium selenium, String index) {
		return selenium.getSelectedLabel("//select[@name='ddlArea_" + index
				+ "']");
	}

	/**
	 * @param selenium
	 * @param index
	 *            It should be the format as "1"! offset from "1"!
	 * @param state
	 *            should be the label of the option
	 */
	public void setPhoneState(DefaultAjaxSelenium selenium, String index,
			String state) {
		selenium.select("//select[@name='ddlArea_" + index + "']", state);
	}

	// set and get emails
	/**
	 * @param selenium
	 * @param index
	 *            It should be the format as "1"! offset from "1"!
	 * @return
	 */
	public String getEmailValue(DefaultAjaxSelenium selenium, String index) {
		return selenium.getText("//input[@name='txtMail_" + index + "']");
	}

	public void setEmailValue(DefaultAjaxSelenium selenium, String index,
			String email) {
		selenium.type("//input[@name='txtMail_" + index + "']", email);
	}

	/**
	 * @param selenium
	 * @param index
	 *            It should be the format as "1"! offset from "1"!
	 * @return label of the selected option
	 */
	public String getEmailType(DefaultAjaxSelenium selenium, String index) {
		return selenium.getSelectedLabel("//select[@name='ddlMailType_" + index
				+ "']");
	}

	public void setEmailType(DefaultAjaxSelenium selenium, String index,
			String type) {
		selenium.select("//select[@name='ddlMailType_" + index + "']", type);
	}
	
	/**
	 * Check the check box to share the team or contact.
	 * @param selenium
	 */
	public void checkShareBox(DefaultAjaxSelenium selenium){
		selenium.check("ctl00_content_ckbShare");
	}
	/**UnCheck the check box to not share the team or contact.
	 * @param selenium
	 */
	public void unCheckBox(DefaultAjaxSelenium selenium){
		selenium.uncheck("ctl00_content_ckbShare");
	}
	

	// actions

	public void clickPhoneAddLink(DefaultAjaxSelenium selenium) {
		selenium.click("btnPhone");
		try{
			Thread.sleep(3000);	
		}catch (Exception e){
			e.printStackTrace();
		}
		
	}

	/**
	 * @param selenium
	 * @param index
	 *            : the index of the phone. It should be the format as "1"!
	 *            offset from "1"!
	 */
	public void clickPhoneDeleteLink(DefaultAjaxSelenium selenium, String index) {
		selenium.click("//input[@id='btnDel" + index + "']");
	}

	public void clickEmailAddLink(DefaultAjaxSelenium selenium) {
		selenium.click("btnMail");
		try{
			Thread.sleep(3000);	
		}catch (Exception e){
			e.printStackTrace();
		}
	}

	/**
	 * @param selenium
	 * @param index
	 *            : the index of the phone. It should be the format as "1"!
	 *            offset from "1"!
	 */
	public void clickEmailDeleteLink(DefaultAjaxSelenium selenium, String index) {
		selenium.click("//input[@id='btnDel" + index + "']");
	}

	/**
	 * @param selenium
	 *            click the add contact button to add one contact.
	 */
	public void clickAddContactButton(DefaultAjaxSelenium selenium) {
		selenium.click("ctl00_content_btnAddPerson");
		this.waitForPageToLoad(selenium);
	}

	/**
	 * select one contact after selecting one team.
	 * 
	 * @param selenium
	 * @param name
	 */
	public void selectContact(DefaultAjaxSelenium selenium, String name) {
		selenium.click("link=" + name);
		this.waitForPageToLoad(selenium);
	}

	/**
	 * Change the team while editing the contact.
	 * 
	 * @param selenium
	 * @param teamName
	 * 
	 */
	public void selectAnotherTeam(DefaultAjaxSelenium selenium, String teamName) {
		selenium.select("ctl00_content_ddlGroup", teamName);
	}

	public void searchbyName(DefaultAjaxSelenium selenium, String keyWord) {
		selenium.type("wd", keyWord);
		selenium.click("ctl00_content_btnSearch");
		this.waitForPageToLoad(selenium);
	}

}
